/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipo.mm.web.util.security;

import java.util.Collection;
import java.util.Vector;

/**
 *
 * @author makcro
 */
public class SecurityManager {

    public static Integer SHOW_MAIN_PAGE = 0;
    public static Integer SHOW_CLOSE_PAGE = -1;

    public static Integer CREATE_USER_PRIVILEGE = 1;
    public static Integer DELETE_USER_PRIVILEGE = 2;
    public static Integer EDIT_USER_PRIVILEGE = 3;
    public static Integer READ_USER_PRIVILEGE = 4;
    public static Integer CREATE_CITY_PRIVILEGE = 5;
    public static Integer DELETE_CITY_PRIVILEGE = 6;
    public static Integer EDIT_CITY_PRIVILEGE = 7;
    public static Integer READ_CITY_PRIVILEGE = 8;
    public static Integer CREATE_INSTITUTION_PRIVILEGE = 9;
    public static Integer DELETE_INSTITUTION_PRIVILEGE = 10;
    public static Integer EDIT_INSTITUTION_PRIVILEGE = 11;
    public static Integer READ_INSTITUTION_PRIVILEGE = 12;
    public static Integer CREATE_IFAMILY_PRIVILEGE = 13;
    public static Integer DELETE_IFAMILY_PRIVILEGE = 14;
    public static Integer EDIT_IFAMILY_PRIVILEGE = 15;
    public static Integer READ_IFAMILY_PRIVILEGE = 16;
    public static Integer CREATE_IREGION_PRIVILEGE = 17;
    public static Integer DELETE_IREGION_PRIVILEGE = 18;
    public static Integer EDIT_IREGION_PRIVILEGE = 19;
    public static Integer READ_IREGION_PRIVILEGE = 20;
    public static Integer CREATE_ITYPE_PRIVILEGE = 21;
    public static Integer DELETE_ITYPE_PRIVILEGE = 22;
    public static Integer EDIT_ITYPE_PRIVILEGE = 23;
    public static Integer READ_ITYPE_PRIVILEGE = 24;
    public static Integer CREATE_REPRESENTATIVE_PRIVILEGE = 25;
    public static Integer DELETE_REPRESENTATIVE_PRIVILEGE = 26;
    public static Integer EDIT_REPRESENTATIVE_PRIVILEGE = 27;
    public static Integer READ_REPRESENTATIVE_PRIVILEGE = 28;
    public static Integer CREATE_MEETING_PRIVILEGE = 29;
    public static Integer DELETE_MEETING_PRIVILEGE = 30;
    public static Integer EDIT_MEETING_PRIVILEGE = 31;
    public static Integer READ_MEETING_PRIVILEGE = 32;
    public static Integer SEND_BULK_MAIL_PRIVILEGE = 33;
    public static Integer READ_LOG_PRIVILEGE = 34;
    public static Integer READ_ACTIONS_PRIVILEGE = 35;
    public static Integer CREATE_ACTIONS_PRIVILEGE = 36;
    public static Integer EDIT_ACTIONS_PRIVILEGE = 37;
    public static Integer DELETE_ACTIONS_PRIVILEGE = 38;
    public static Integer PRINT_MAIL_PRIVILEGE = 39;

    
    private Collection<Integer> guestUserPrivileges = new Vector<Integer>();
    private Collection<Integer> normalUserPrivileges = new Vector<Integer>();
    private Collection<Integer> adminUserPrivileges = new Vector<Integer>();

    public static Integer USER_TYPE_GUEST = 1;
    public static Integer USER_TYPE_NORMAL = 2;
    public static Integer USER_TYPE_ADMIN = 3;

    public Collection<Integer> getPrivilegesByUserType(Integer userType) {
        if (USER_TYPE_NORMAL.equals(userType)) {
            return normalUserPrivileges;
        } else if (USER_TYPE_GUEST.equals(userType)) {
            return guestUserPrivileges;
        } else {
            return adminUserPrivileges;
        }
    }

    public SecurityManager() {
        setGuestPrivileges();
        setNormalUserPrivileges();
        setAdminUserPrivileges();
    }

    private void setGuestPrivileges(){

        guestUserPrivileges.add(SHOW_MAIN_PAGE);

        guestUserPrivileges.add(READ_CITY_PRIVILEGE);
        guestUserPrivileges.add(READ_INSTITUTION_PRIVILEGE);
        guestUserPrivileges.add(READ_IREGION_PRIVILEGE);
        guestUserPrivileges.add(READ_ITYPE_PRIVILEGE);
        guestUserPrivileges.add(READ_MEETING_PRIVILEGE);
        guestUserPrivileges.add(READ_REPRESENTATIVE_PRIVILEGE);
        guestUserPrivileges.add(READ_IFAMILY_PRIVILEGE);
        guestUserPrivileges.add(READ_ACTIONS_PRIVILEGE);
        guestUserPrivileges.add(SHOW_CLOSE_PAGE);
    }

    private void setNormalUserPrivileges(){
        normalUserPrivileges.addAll(guestUserPrivileges);

        normalUserPrivileges.add(CREATE_CITY_PRIVILEGE);
        normalUserPrivileges.add(CREATE_IFAMILY_PRIVILEGE);
        normalUserPrivileges.add(CREATE_INSTITUTION_PRIVILEGE);
        normalUserPrivileges.add(CREATE_IREGION_PRIVILEGE);
        normalUserPrivileges.add(CREATE_ITYPE_PRIVILEGE);
        normalUserPrivileges.add(CREATE_MEETING_PRIVILEGE);
        normalUserPrivileges.add(CREATE_REPRESENTATIVE_PRIVILEGE);

        normalUserPrivileges.add(EDIT_CITY_PRIVILEGE);
        normalUserPrivileges.add(EDIT_INSTITUTION_PRIVILEGE);
        normalUserPrivileges.add(EDIT_IREGION_PRIVILEGE);
        normalUserPrivileges.add(EDIT_ITYPE_PRIVILEGE);
        normalUserPrivileges.add(EDIT_MEETING_PRIVILEGE);
        normalUserPrivileges.add(EDIT_REPRESENTATIVE_PRIVILEGE);
        normalUserPrivileges.add(EDIT_IFAMILY_PRIVILEGE);
        
        normalUserPrivileges.add(READ_LOG_PRIVILEGE);
        normalUserPrivileges.add(CREATE_ACTIONS_PRIVILEGE);
        normalUserPrivileges.add(EDIT_ACTIONS_PRIVILEGE);

        normalUserPrivileges.add(SEND_BULK_MAIL_PRIVILEGE);
        normalUserPrivileges.add(PRINT_MAIL_PRIVILEGE);

    }

    private void setAdminUserPrivileges(){
        adminUserPrivileges.addAll(guestUserPrivileges);
        adminUserPrivileges.addAll(normalUserPrivileges);

        adminUserPrivileges.add(READ_USER_PRIVILEGE);
        adminUserPrivileges.add(EDIT_USER_PRIVILEGE);
        adminUserPrivileges.add(CREATE_USER_PRIVILEGE);
        adminUserPrivileges.add(DELETE_USER_PRIVILEGE);
                
        adminUserPrivileges.add(DELETE_CITY_PRIVILEGE);
        adminUserPrivileges.add(DELETE_IFAMILY_PRIVILEGE);
        adminUserPrivileges.add(DELETE_INSTITUTION_PRIVILEGE);
        adminUserPrivileges.add(DELETE_IREGION_PRIVILEGE);
        adminUserPrivileges.add(DELETE_ITYPE_PRIVILEGE);
        adminUserPrivileges.add(DELETE_MEETING_PRIVILEGE);
        adminUserPrivileges.add(DELETE_REPRESENTATIVE_PRIVILEGE);
        adminUserPrivileges.add(DELETE_USER_PRIVILEGE);
       
        adminUserPrivileges.add(READ_LOG_PRIVILEGE);
        adminUserPrivileges.add(DELETE_ACTIONS_PRIVILEGE);
        
        adminUserPrivileges.add(SEND_BULK_MAIL_PRIVILEGE);
        adminUserPrivileges.add(PRINT_MAIL_PRIVILEGE);

    }


}
